#include "SmothMoveAnimation.h"
#include "GraphicalElement.h"
#include <cmath>

SmothMoveAnimation::SmothMoveAnimation(const Position& start, const Position& end, unsigned long duration)
    : Animation(duration), start(start), end(end)
{
}

SmothMoveAnimation::~SmothMoveAnimation()
{
}

void SmothMoveAnimation::update(double factor)
{
    if (factor > 1)
    {
        current = end;
        return;
    }
    double sinf = sin(factor*3.1415/2);
    current = start.scale(1-sinf) + end.scale(sinf);
}

void SmothMoveAnimation::render(const Position& parent)
{
    element->setPosition(current);
    Animation::render(parent);
}
